{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3090e144",
   "metadata": {},
   "source": [
    "# 列表入门\n",
    "> 1.序列中每个值都有对应的位置值是：索引（默认第一个索引是0，第二个是1...以此类推）\n",
    "> 2.列表的操作：索引，切片，加，乘，检查成员"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ead35f6f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 列表可包含任何数据类型的元素，单个列表的元素无须为同一类型\n",
    "list1 = [\"taobao\", 10011, \"xiaohong\"]\n",
    "# 除了使用[ ]创建列表外，python还提供一个内置函数list( )，可将其他数据类型转换为列表类型"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d452caeb",
   "metadata": {},
   "source": [
    "# 列表的认识"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "5529d47e",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 引入列表\n",
    "user_data_list = [[\"zhichao\",123435,19],[\"Jack\",463434,23],[\"Alex\",583495,25],[\"Marry\",438294,27]]\n",
    "# user_daye_list =[\"junbin\",\"jack\",\"kaijun\",\"mary\"]\n",
    "# password_list = [12345,23455,34567]\n",
    "# age_list = [23,23,23,23]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "133abbe8",
   "metadata": {},
   "source": [
    "##  从左往右取值（index & slice）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "79655cf4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Alex', 583495, 25]\n",
      "[['zhichao', 123435, 19], ['Jack', 463434, 23], ['Alex', 583495, 25]]\n",
      "[['zhichao', 123435, 19], ['Jack', 463434, 23], ['Alex', 583495, 25]]\n"
     ]
    }
   ],
   "source": [
    "# 从左往右取值（index & slice）\n",
    "print(user_data_list[2])\n",
    "# 切片 slice ，右边的值取不到 例如[0:3] 索引为3的值取不到\n",
    "print(user_data_list[0:3])\n",
    "# 当从0开始取值时，0 可以忽略不写\n",
    "print(user_data_list[:3])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f33f8f83",
   "metadata": {},
   "source": [
    "## 从右往左取值(index & slice)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "f4e94a33",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Alex', 583495, 25]\n",
      "[['Jack', 463434, 23], ['Alex', 583495, 25]]\n",
      "[]\n",
      "[['Jack', 463434, 23], ['Alex', 583495, 25], ['Marry', 438294, 27]]\n"
     ]
    }
   ],
   "source": [
    "print(user_data_list[-2])\n",
    "# 切片 slice ，右边的值取不到 例如[-3:-1] 索引为-1的值取不到\n",
    "print(user_data_list[-3:-1])\n",
    "# 如果取值为空：说明slice写错了 例如[-3:0]\n",
    "# 如果要取到最后一个值，不能写0，直接省略不写\n",
    "print(user_data_list[-3:0])\n",
    "print(user_data_list[-3:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "64e63422",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[['zhichao', 123435, 19], ['Jack', 463434, 23], ['Alex', 583495, 25], ['Marry', 438294, 27]]\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "'list' object is not callable",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-32-e22b9bb1dd0d>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      8\u001b[0m \u001b[0m如果没有指定步长值\u001b[0m\u001b[0;31m，\u001b[0m\u001b[0m则默认步长为1\u001b[0m\u001b[1;33m.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      9\u001b[0m '''\n\u001b[1;32m---> 10\u001b[1;33m \u001b[0mnum\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mlist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m10\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     11\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnum\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     12\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnum\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;36m6\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: 'list' object is not callable"
     ]
    }
   ],
   "source": [
    "# *****重要*****\n",
    "print(user_data_list[:])\n",
    "\n",
    "# 步长，list列表slice ：[start:stop:step]\n",
    "'''\n",
    "如果没有指定开始值，则默认为0；\n",
    "如果没有指定结束指，则取列表允许的最大值；\n",
    "如果没有指定步长值，则默认步长为1.\n",
    "'''\n",
    "num = list(range(10))\n",
    "print(num)\n",
    "print(num[0:6:2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1f298e63",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
